gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\linear\anderson\pandr2d.m

    function [handler]=pandr2d(MI,SIGMA,I,alpha1,theta1,handler,anim,alpha2,theta2)
% PANDR2D displays solution of Generalized Anderson's task in 2D.
% [handler]=pandr2d(MI,SIGMA,I,alpha1,theta1,handler,anim,alpha2,theta2)
%
% PANDR2D plots given solution of the Generalized Anderson`s task (GAT) in
%  2-dimensional feature space. This function plots separation line 
%  (2D case of the GAT) and input classes which are symbolized by sets 
%  of ellipsoids.
%
%  Input arguments MI, SIGMA and I describe input mixture of normal 
%  distributions. The pair of input arguments {alpha,theta} describes 
%  separation line which is particular solution of the GAT. 
%
%  For information on the meaning of the arguments refer to help of 
%  functions solving the GAT (ganders,ganders2,eanders etc.).
%
%  When the quadruple of input parameters handler, anim, alpha2 and theta2
%  enter function then a change of the solution is depicted too. The pair
%  alpha1, theta1 is old solution and alpha2, theta2 is new solution. The
%  argument handler contains information about graphics abjects used 
%  in the last call of the function and returned in output variable handle. 
%  When the argument anim=1 then the change is animated.
%
% See also PANDR2D, ANDRDEMO, GANDERS, GANDERS2, EANDERS, OANDERS.
%

% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac
% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz
% Written Vojtech Franc (diploma thesis) 23.11.1999, 11.5.2000
% Modifications
% 24. 6.00 V. Hlavac, comments polished.
% 2.8.00 V.Franc, comments changed

% constants
BORDER=0.95;
POINT_SIZE=8;
POINT_COLOR='k';
POINT_WIDTH=2;
LINE_WIDTH=1;
LINE_COLOR='k';
ELLIPSE_WIDTH=1;
INTERPOL=50;
ANIM_DIF=20;

% handles input arguments
if nargin < 7,
   anim=0;
end
if nargin < 6,
   handler=-1;
end

alpha1=alpha1(:);     % alpha1 will column

% number of ellipses
N=size(MI,2);
% dimension, must be equal to 2
DIM=size(MI,1);

if handler==-1,
   % proportions of a separation line
   window=axis*BORDER;
else
   % proportions of a separation line
   window=getaxis(handler(N+3))*BORDER;
end;

if anim==0,

   % computes minimal distance among the line alpha*x=theta and
   % the elipses (x-MI)'*inv(SIGMA)*(x-MI)
   [R,inx]=min( abs(alpha1'*MI-theta1)./sqrt( reshape(alpha1'*SIGMA,DIM,N)'*alpha1 )' );


   if handler==-1,
      % first painting

      % ellipses
      for i=1:N,
         mi=MI(:,i);
         sigma=SIGMA(:,(i-1)*DIM+1:i*DIM);
%%%         isg=inv(sigma);

%%%         [x,y]=ellipse(isg,INTERPOL,R,mi);
         [x,y]=ellips(mi,sigma,R,INTERPOL);

         handler(i)=plot(x,y,'Color',color(I(i)),...
            'EraseMode','xor',...
            'LineWidth',ELLIPSE_WIDTH,...
            'UserData',sigma);
      end
      % line
      [x1,y1,x2,y2]=cliplin1(alpha1,theta1,window);
      handler(N*2+1)=line([x1 x2],[y1 y2],...
         'LineWidth',LINE_WIDTH,...
         'Color',LINE_COLOR,...
         'EraseMode','xor');

      % pull point
      mi=MI(:,inx);
      sigma=SIGMA(:,(inx-1)*DIM+1:inx*DIM);
      x0=mi-(alpha1'*mi-theta1)*sigma*alpha1/(alpha1'*sigma*alpha1);
      handler(N*2+2)=line(x0(1),x0(2),...
         'LineStyle','none',...
         'Color',POINT_COLOR,...
         'MarkerSize',POINT_SIZE,...
         'LineWidth',POINT_WIDTH,...
         'Marker','x',...
         'EraseMode','xor');

       handler(N+3)=gca;

   else % if handler==-1,
      % at least second painting

      % hide all objects
%      set(handler,'Visible','off');

      % ellipses
      for i=1:N,
         mi=MI(:,i);
         sigma=get(handler(i),'UserData');
         [x,y]=ellips(mi,sigma,R,INTERPOL);
         set(handler(i),'XData',x,'YData',y,'Visible','on');
      end

      % line
      [x1,y1,x2,y2]=cliplin1(alpha1,theta1,window);
      set(handler(N*2+1),'XData',[x1 x2],'YData',[y1 y2],'Visible','on');

      % pull point
      mi=MI(:,inx);
      sigma=SIGMA(:,(inx-1)*2+1:inx*2);
      x0=mi-(alpha1'*mi-theta1)*sigma*alpha1/(alpha1'*sigma*alpha1);
      set(handler(N*2+2),'XData',x0(1),'YData',x0(2),'Visible','on');

   end % if handler==-1,

else % if anim==0,

   alpha2=alpha2(:);   % alpha2 will column

   % computes number of the animation steps
   [x11,y11,x12,y12]=cliplin1(alpha1,theta1,window);
   [x21,y21,x22,y22]=cliplin1(alpha2,theta2,window);

   difa=max([sqrt((x11-x21)^2+(y11-y21)^2),sqrt((x11-x21)^2+(y11-y21)^2)]);
   difw=min([window(4)-window(3), window(2)-window(1)]);
   nsteps=max([1,ceil(ANIM_DIF*(difa/difw))]);

   % play
   for i=1:nsteps,
      k=i/nsteps;
      alpha=(1-k)*alpha2+k*alpha1;          % smooth transition of alpha
      theta=(1-k)*theta2+k*theta1;                      % --//--                        theta

      % recursion
      handler=andr2d(MI,SIGMA,I,alpha,theta,handler,0);
   end

end % if anim==0,